package smarture;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Map.Entry;

public class Utils {

	public static int calculateReward(int healthUnitOld, int healthUnitNew,
			ArrayList<Integer> healthEnemysOld, ArrayList<Integer> healthEnemysNew) {

		int sumOld = 0;
		for (int i : healthEnemysOld) {
			sumOld += (i - healthUnitOld);
		}

		int sumNew = 0;
		for (int i : healthEnemysNew) {
			sumNew += (i - healthUnitNew);
		}

		return sumOld - sumNew;
	}

	public static int calculateRewards1(int healthUnitOld, int healthUnitNew,
			HashMap<Integer, Integer> healthEnemyOld,
			HashMap<Integer, Integer> healthEnemyNew) {
		int sumOld = 0, sumNew = 0;

		@SuppressWarnings("rawtypes")
		Iterator it = healthEnemyOld.entrySet().iterator();
		while (it.hasNext()) {
			@SuppressWarnings("unchecked")
			Map.Entry<Integer, Integer> pairs = (Entry<Integer, Integer>) it.next();
			sumOld += (pairs.getValue() + healthUnitOld);
			if (healthEnemyNew.get(pairs.getKey()) == null) {
				sumNew += (healthUnitNew);
			} else {
				sumNew += (healthUnitNew + healthEnemyNew.get(pairs.getKey()));
			}
		}

		return sumOld - sumNew;
	}

}
